package com.project.myshop.dao.impl;

import com.project.myshop.dao.UserDao;
import com.project.myshop.entity.User;
import com.project.myshop.util.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    private QueryRunner qr=new QueryRunner(DBUtils.getDataSource());
    @Override
    public User findUserByName(String username) throws SQLException {
        String sql= "select " +
                "`u_id` 'uid',`u_name` 'uname',`u_password` 'upassword'," +
                "`u_email` 'uemail',`u_sex` 'usex',`u_status` 'ustatus'," +
                "`u_code` 'ucode',`u_role` 'urole'" +
                "from user  " +
                "where u_name=?";
        return qr.query(sql,new BeanHandler<>(User.class),username);
    }
}
